package utils;

import org.apache.log4j.Logger;
import org.testng.Reporter;

public class ReportWriter {

    private static final Logger LOGGER = Logger.getLogger(ReportWriter.class);

    // ****************** Default message content ********************
    private static final String SEPARATOR = "***********************************************************************";

    private static final String INFO_LOG = "INFO: \"%s\"";
    private static final String ERROR_LOG = "ERROR: \"%s\"";
    private static final String PAGE_IS_LOADED = "PASS: Target page is loaded \"%s\"!";
    private static final String TEST_FINISHED_SUCCESS = "INFO: test \"%s\" is PASS";
    private static final String PROPERTY_NOT_LOADED = "FAIL: Could not load property \"%s\"!";
    private static final String DRIVER_UNKNOWN = "ERROR: Unknown web-driver \"%s\"!";


    public static String info (String str)
    {
        LOGGER.info(String.format(INFO_LOG, str));
        Reporter.log(String.format(INFO_LOG, str));
        return String.format(INFO_LOG, str);
    }

    public static String error (String str)
    {
        LOGGER.error(String.format(ERROR_LOG, str));
        Reporter.log(String.format(ERROR_LOG, str));
        return String.format(ERROR_LOG, str);
    }

    public static String pageLoaded (String str)
    {
        LOGGER.info(String.format(PAGE_IS_LOADED, str));
        Reporter.log(String.format(PAGE_IS_LOADED, str));
        return String.format(PAGE_IS_LOADED, str);
    }

    public static void logTestFinishSuccess(String str) {
        LOGGER.info(String.format(TEST_FINISHED_SUCCESS,str));
        LOGGER.info(SEPARATOR);
        Reporter.log(String.format(TEST_FINISHED_SUCCESS, str));
        Reporter.log(SEPARATOR);
    }

    public static String logPropertyNotLoaded(String s)
    {
        LOGGER.error(String.format(PROPERTY_NOT_LOADED, s));
        Reporter.log(String.format(PROPERTY_NOT_LOADED, s));
        return String.format(PROPERTY_NOT_LOADED, s);
    }

    public static String errorDriverUnknown (String name)
    {
        LOGGER.error(String.format(DRIVER_UNKNOWN, name));
        Reporter.log(String.format(DRIVER_UNKNOWN, name));
        return String.format(DRIVER_UNKNOWN, name);
    }


}